<?php
/**
 * @征信报告类
 * 1、征信报告列表
 * 2、征信报告添加或者移除
 * 3、征信报告的舆情list
 * @作者
 * 万全强（php）
 */
namespace app\controller;

use app\controller\HomeBase;
use think\facade\Db;


use app\validate\ApplycomreportValidate;
use app\model\ApplycomreportModel;
use app\model\CompanyModel;

class Applycomreport extends HomeBase
{
	
	private $ApplycomreportValidate;
	private $ApplycomreportModel;
	
	public function __construct(){
		
		parent::__construct();
		
		$this->ApplycomreportValidate=new ApplycomreportValidate();
		$this->ApplycomreportModel=new ApplycomreportModel();
		
	}
	/**
	 * 征信报告列表
	 *
	 * @return void
	 */
	public function GetApplycomreportList()
	{
		$param=request()->param();
		$where="1=1 and status =1 ";
		if(isset($param['keywords'])&&!empty($param['keywords'])){
			$where.=" and name like '%".trim($param['keywords'])."%'";
		}
		if(isset($param['type'])&&!empty($param['type'])){
			$where.=" and type = ".intval($param['type']);
		}
		$where.=" and user_id=".$this->user_id;
		
		$res=$this->ApplycomreportModel->GetList($where);
		return json(['status'=>1,'msg'=>'获取成功','data'=>$res]);
	}
	
	/**
	 * 征信报告添加
	 *
	 * @return void
	 */
	public function ApplycomreportAdd()
	{
		$param=request()->param();
		$identification=isset($param['identification'])?trim($param['identification']):'';
		//表单验证
		try {
			$re=$this->validate($param,'app\validate\ApplycomreportValidate');
		} catch (\Exception $e) {
			return json(['status'=>0,'msg'=>$e->error,'data'=>[]]);
		}
		$CompanyModel=new CompanyModel();
		$company_name=$CompanyModel->GetCompanyNameByIdentification($identification);
		if(empty($company_name)){
			return json(['status'=>0,'msg'=>'企业信息不存在','data'=>[]]);
		}
		$param['name']=$company_name;
		$param['user_id']=$this->user_id;
		//判断是否存在
		$info=$this->ApplycomreportModel->GetDetail($param);
		//管理表
		if($info){
			$this->ApplycomreportModel->UpdateStatus($info['id'],1);
		}else{
			$id=$this->ApplycomreportModel->AddData($param);
		}
		
		return json(['status'=>1,'msg'=>'操作成功','data'=>[]]);
	}
	
}
